//
//  JSKeyboardFontCell.m
//  JigSaw
//
//  Created by 贺勇 on 15/3/14.
//  Copyright (c) 2015年 LITB. All rights reserved.
//

#import "JSKeyboardFontCell.h"
#import <UIImageView+AFNetworking.h>

@implementation JSKeyboardFontCellModel

@end

@interface JSKeyboardFontCell ()

@property (nonatomic, weak) IBOutlet UIImageView * fontIV;
@property (nonatomic, weak) IBOutlet UILabel * fontPackageSizeLabel;
@property (nonatomic, weak) IBOutlet UIButton * downloadBtn;
@property (nonatomic, weak) IBOutlet UIButton * cancelBtn;
@property (nonatomic, weak) IBOutlet UIView * progressView;
@property (nonatomic, weak) IBOutlet UIImageView * okIV;

@property (nonatomic, strong) UILabel * progressLabel;
@end

@implementation JSKeyboardFontCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setCellModel:(JSKeyboardFontCellModel *)cellModel
{
    _cellModel = cellModel;
    self.fontIV.image = cellModel.fontImage;
    if (cellModel.type == JSKeyboardFontCellTypeNeedDownload) {
        self.fontPackageSizeLabel.text = [NSString stringWithFormat:@"%.1lfM", cellModel.fontSize];
    }
    else if (cellModel.type == JSKeyboardFontCellTypeDownloading)
    {
        CGFloat width = CGRectGetWidth(self.progressView.bounds);
        CGFloat height = CGRectGetHeight(self.progressView.bounds);
        CGFloat progressWidth = cellModel.progress / 100.0 * width;
        [self.progressLabel removeFromSuperview];
        self.progressLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, progressWidth, height)];
        self.progressLabel.backgroundColor = [UIColor greenColor];
        [self.progressView addSubview:self.progressLabel];
    }
}

- (IBAction)downloadAction:(id)sender
{
    if (self.downloadBlock) {
        self.downloadBlock(self);
    }
}

- (IBAction)cancelAction:(id)sender
{
    if (self.cancelBlock) {
        self.cancelBlock(self);
    }
}

@end
